<html>
<head><meta charset="utf-8"><title>long term plan for const pattern codegen #66120 · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html">long term plan for const pattern codegen #66120</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="181121625"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181121625" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181121625">(Nov 19 2019 at 15:27)</a>:</h4>
<p>I spent some time trying to resolve long-standing issues with our <code>#[structural_match]</code> system that tries to restrict the set of consts that are allowed to be used in a pattern context.</p>



<a name="181121791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181121791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181121791">(Nov 19 2019 at 15:28)</a>:</h4>
<p>see also <a href="https://github.com/rust-lang/rfcs/issues/1445" target="_blank" title="https://github.com/rust-lang/rfcs/issues/1445">rfc#1445</a></p>



<a name="181121850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181121850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181121850">(Nov 19 2019 at 15:29)</a>:</h4>
<p>anyway, <span class="user-mention" data-user-id="119009">@eddyb</span> pointed out in a review of my PR <a href="https://github.com/rust-lang/rust/issues/66120" target="_blank" title="https://github.com/rust-lang/rust/issues/66120">#66120</a> that it might be best to scrap my proposed approach and instead use something based on const-qualification</p>



<a name="181121906"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181121906" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181121906">(Nov 19 2019 at 15:29)</a>:</h4>
<p>specifically see the discussion <a href="https://github.com/rust-lang/rust/pull/66120#discussion_r343227532" target="_blank" title="https://github.com/rust-lang/rust/pull/66120#discussion_r343227532">here</a></p>



<a name="181121998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181121998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181121998">(Nov 19 2019 at 15:30)</a>:</h4>
<p>And so I wanted to try to get feedback here on the matter, about whether it makes more sense to try to apply <code>mir_const_qualif</code> here</p>



<a name="181122342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181122342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181122342">(Nov 19 2019 at 15:33)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="118594">@ecstatic-morse</span> looking at the actual code this seems pretty easy (compared to analyzing HIR)</p>



<a name="181139175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181139175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181139175">(Nov 19 2019 at 18:18)</a>:</h4>
<p><span class="user-mention" data-user-id="116083">@pnkfelix</span> I just looked at the issue referenced by your PR and <code>check_consts::Qualif</code> seems like the right tool for this. We'd have to do this in <code>mir_const_qualif</code> for <em>all</em> <code>const</code>s since we want to get this cross crate right?</p>



<a name="181139538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181139538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181139538">(Nov 19 2019 at 18:22)</a>:</h4>
<p>as opposed to doing it lazily for consts that appear in a pattern?</p>



<a name="181143965"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181143965" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181143965">(Nov 19 2019 at 19:08)</a>:</h4>
<p>Strategy of current PR is to handle cross-crates by falling back on a conservative type-based analysis</p>



<a name="181144003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181144003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181144003">(Nov 19 2019 at 19:08)</a>:</h4>
<p>So it doesn’t <em>have</em> to be done there. But it probably is something to consider</p>



<a name="181144035"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181144035" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181144035">(Nov 19 2019 at 19:09)</a>:</h4>
<p>type-based analysis will anyway be needed for associated consts</p>



<a name="181144202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181144202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181144202">(Nov 19 2019 at 19:10)</a>:</h4>
<p>Okay, we can it either way. It just affects whether the code goes in <code>mir_const_qualif</code> or you use the API directly.</p>



<a name="181144298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181144298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181144298">(Nov 19 2019 at 19:11)</a>:</h4>
<p>Also, the churn that <span class="user-mention silent" data-user-id="119009">eddyb</span> mentioned in their comment has abated somewhat, so this shouldn't be too hard.</p>



<a name="181144525"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181144525" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181144525">(Nov 19 2019 at 19:14)</a>:</h4>
<p>Basically, you'll add an implementer of the <a href="https://github.com/rust-lang/rust/blob/618b01f9fa0a6b4e7e2ce5b3409abe104b80c4a8/src/librustc_mir/transform/check_consts/qualifs.rs#L22" target="_blank" title="https://github.com/rust-lang/rust/blob/618b01f9fa0a6b4e7e2ce5b3409abe104b80c4a8/src/librustc_mir/transform/check_consts/qualifs.rs#L22"><code>Qualif</code></a> trait for structural matching, probably very similar to the existing one for <a href="https://github.com/rust-lang/rust/blob/618b01f9fa0a6b4e7e2ce5b3409abe104b80c4a8/src/librustc_mir/transform/check_consts/qualifs.rs#L277" target="_blank" title="https://github.com/rust-lang/rust/blob/618b01f9fa0a6b4e7e2ce5b3409abe104b80c4a8/src/librustc_mir/transform/check_consts/qualifs.rs#L277"><code>Drop</code></a>.</p>



<a name="181144694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181144694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181144694">(Nov 19 2019 at 19:16)</a>:</h4>
<p>Then use it for a dataflow analysis as is done in the <a href="https://github.com/rust-lang/rust/blob/618b01f9fa0a6b4e7e2ce5b3409abe104b80c4a8/src/librustc_mir/transform/check_consts/validation.rs#L185" target="_blank" title="https://github.com/rust-lang/rust/blob/618b01f9fa0a6b4e7e2ce5b3409abe104b80c4a8/src/librustc_mir/transform/check_consts/validation.rs#L185">MIR const-checker</a></p>



<a name="181144959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181144959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181144959">(Nov 19 2019 at 19:19)</a>:</h4>
<p>currently those other qualifs look to see if there was a mutable borrow of that local (that's what <code>IndirectlyMutableLocals</code> is for). You probably want to do this, even though we don't allow mutable references in <code>const</code>s at the moment.</p>



<a name="181145188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181145188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181145188">(Nov 19 2019 at 19:21)</a>:</h4>
<p>If you want to make this part of <code>mir_const_qualif</code> (and thus allow it to work cross-crate at the cost of running another dataflow pass on every const), you would just have to add the new <code>Qualif</code> to <code>ConstQualifs</code> in <code>rustc::mir</code> and modify <a href="https://github.com/rust-lang/rust/blob/618b01f9fa0a6b4e7e2ce5b3409abe104b80c4a8/src/librustc_mir/transform/check_consts/validation.rs#L116" target="_blank" title="https://github.com/rust-lang/rust/blob/618b01f9fa0a6b4e7e2ce5b3409abe104b80c4a8/src/librustc_mir/transform/check_consts/validation.rs#L116"><code>Qualifs::in_return_place</code></a> to extract it.</p>



<a name="181145368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181145368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181145368">(Nov 19 2019 at 19:23)</a>:</h4>
<p>Otherwise you can roll your own code using <a href="https://github.com/rust-lang/rust/blob/618b01f9fa0a6b4e7e2ce5b3409abe104b80c4a8/src/librustc_mir/transform/check_consts/validation.rs#L47" target="_blank" title="https://github.com/rust-lang/rust/blob/618b01f9fa0a6b4e7e2ce5b3409abe104b80c4a8/src/librustc_mir/transform/check_consts/validation.rs#L47"><code>FlowSensitiveAnalysis</code></a></p>



<a name="181186330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181186330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181186330">(Nov 20 2019 at 07:56)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> are you opposed to me landing the PR <a href="https://github.com/rust-lang/rust/issues/66120" target="_blank" title="https://github.com/rust-lang/rust/issues/66120">#66120</a> as is (or with slight tweaks), and filing an issue for the mir_const_qualif-based approach?</p>



<a name="181216523"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181216523" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181216523">(Nov 20 2019 at 15:19)</a>:</h4>
<p><span class="user-mention" data-user-id="116083">@pnkfelix</span> well, other than HIR code that doesn't need to exist and is a dozen times larger than the equivalent Qualif logic,,, (no, I'm not opposed if you don't mind the code being around for a while)</p>



<a name="181216609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181216609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181216609">(Nov 20 2019 at 15:20)</a>:</h4>
<p><span class="user-mention" data-user-id="116083">@pnkfelix</span> would be good to have some write-up in the rustc guide for the new semantics</p>



<a name="181216822"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181216822" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181216822">(Nov 20 2019 at 15:20)</a>:</h4>
<p>maybe an RFC as well if you change the approach so that we don't start accepting a bunch more code without some design input</p>



<a name="181217010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181217010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181217010">(Nov 20 2019 at 15:21)</a>:</h4>
<p>I'm not happy about the cross-crate distinction, it reminds me of how <code>Enum::Variant as uN</code> in a constant would only work same-crate :P</p>



<a name="181217036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181217036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181217036">(Nov 20 2019 at 15:21)</a>:</h4>
<p>but conservative type-based reasoning that <em>still works</em> is better than nothing</p>



<a name="181855022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181855022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181855022">(Nov 25 2019 at 19:31)</a>:</h4>
<p><span class="user-mention" data-user-id="116083">@pnkfelix</span> I'm happy to work on the <code>mir_const_qualif</code> part of this if you can point me towards an equivalent to <a href="https://github.com/rust-lang/rust/blob/f11759d38c70d3df67135f88a682701c1cf9762a/src/librustc/ty/mod.rs#L2270" target="_blank" title="https://github.com/rust-lang/rust/blob/f11759d38c70d3df67135f88a682701c1cf9762a/src/librustc/ty/mod.rs#L2270">this</a> but for <code>structural_match</code>.</p>



<a name="181907516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181907516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181907516">(Nov 26 2019 at 10:21)</a>:</h4>
<p><span class="user-mention" data-user-id="118594">@ecstatic-morse</span> I think you are asking for the <a href="https://github.com/rust-lang/rust/blob/0f6f66fcdc4abf110171ee06b1a72bdd2883b74f/src/librustc/ty/structural_match.rs#L65" target="_blank" title="https://github.com/rust-lang/rust/blob/0f6f66fcdc4abf110171ee06b1a72bdd2883b74f/src/librustc/ty/structural_match.rs#L65"><code>type_marked_structural</code> function</a></p>



<a name="181907625"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181907625" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181907625">(Nov 26 2019 at 10:22)</a>:</h4>
<p>(which this PR refactors but I think its effect is unchanged.)</p>



<a name="181962335"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181962335" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181962335">(Nov 26 2019 at 20:49)</a>:</h4>
<p><span class="user-mention" data-user-id="116083">@pnkfelix</span>. Yeah that's the basic idea. We would have to store a few more things in <a href="https://github.com/rust-lang/rust/blob/797fd92628842c1f5face9fb93b0fe4f1f9d297f/src/librustc_mir/transform/check_consts/mod.rs#L22" target="_blank" title="https://github.com/rust-lang/rust/blob/797fd92628842c1f5face9fb93b0fe4f1f9d297f/src/librustc_mir/transform/check_consts/mod.rs#L22"><code>check_consts::Item</code></a> to call that directly.</p>
<p>I have zero experience working with an <code>InferCtxt</code>; do we still have access to one in <code>librustc_mir</code>? Ideally <code>TyCtxt</code> would expose a similar method that takes a <code>DefId</code>, but I don't know if that can be efficient.</p>



<a name="181963008"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181963008" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181963008">(Nov 26 2019 at 20:56)</a>:</h4>
<p><code>tcx.infer_ctxt().enter(|infcx| { /* your code here */ )</code></p>



<a name="181963063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181963063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181963063">(Nov 26 2019 at 20:57)</a>:</h4>
<p>There are queries that should allow you to do this as well.</p>



<a name="181963150"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181963150" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181963150">(Nov 26 2019 at 20:58)</a>:</h4>
<p><span class="user-mention" data-user-id="116118">@Matthew Jasper</span> Is it expensive to create a new inference context? It seems like we should have a <code>is_structural_match</code> query for a <code>Ty</code>.</p>



<a name="181963291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181963291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181963291">(Nov 26 2019 at 20:59)</a>:</h4>
<p>It's not that expensive since the <code>'tcx</code>/<code>'gcx</code> unification (there is still currently an unnecessary TLS access on enter and exit)</p>



<a name="181963306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181963306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181963306">(Nov 26 2019 at 20:59)</a>:</h4>
<p>But back to the queries...</p>



<a name="181963497"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181963497" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181963497">(Nov 26 2019 at 21:01)</a>:</h4>
<p><code>type_op_prove_predicate</code> is the one you want I think...</p>



<a name="181963716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181963716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181963716">(Nov 26 2019 at 21:04)</a>:</h4>
<p>The docs for that query say "Do not call this query directly: part of the <code>ProvePredicate</code> type-op". Would this guidance apply here?</p>



<a name="181963735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181963735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181963735">(Nov 26 2019 at 21:04)</a>:</h4>
<p>Actually that still needs an Infcx</p>



<a name="181963748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181963748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181963748">(Nov 26 2019 at 21:04)</a>:</h4>
<p>Yes that</p>



<a name="181964182"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181964182" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181964182">(Nov 26 2019 at 21:09)</a>:</h4>
<p>Okay, I think <code>ProvePredicate</code> and <code>InferCtxt</code> will be enough to get a prototype built. I can get help with performance later.</p>



<a name="181964302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181964302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181964302">(Nov 26 2019 at 21:10)</a>:</h4>
<p>There's an example on how to use these here: <a href="https://github.com/rust-lang/rust/blob/9abc34ed9d34873066a186ac5551d5aad9e783b6/src/librustc_mir/borrow_check/nll/type_check/mod.rs#L2723" target="_blank" title="https://github.com/rust-lang/rust/blob/9abc34ed9d34873066a186ac5551d5aad9e783b6/src/librustc_mir/borrow_check/nll/type_check/mod.rs#L2723">https://github.com/rust-lang/rust/blob/9abc34ed9d34873066a186ac5551d5aad9e783b6/src/librustc_mir/borrow_check/nll/type_check/mod.rs#L2723</a></p>



<a name="181964362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181964362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181964362">(Nov 26 2019 at 21:11)</a>:</h4>
<p>There also needs to be some care that regions are erased when we check this.</p>



<a name="181964430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181964430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181964430">(Nov 26 2019 at 21:12)</a>:</h4>
<p>Which honestly, they should always be in MIR (except for the borrow checker's copy). But that's a future PR.</p>



<a name="181964594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181964594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181964594">(Nov 26 2019 at 21:13)</a>:</h4>
<p>Are we okay using <code>ProvePredicate</code> outside the <code>nll</code> module for things unrelated to lifetimes? Even if regions are erased?</p>



<a name="181964725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181964725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181964725">(Nov 26 2019 at 21:14)</a>:</h4>
<p>It should be fine, just don't copy NLL and unwrap the error. <span aria-label="smiley" class="emoji emoji-1f603" role="img" title="smiley">:smiley:</span></p>



<a name="181964759"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181964759" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181964759">(Nov 26 2019 at 21:15)</a>:</h4>
<p>(that is don't unwrap, even though NLL does)</p>



<a name="181964772"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181964772" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181964772">(Nov 26 2019 at 21:15)</a>:</h4>
<p><code>unreachable_unchecked</code> it is!</p>



<a name="181964784"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181964784" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181964784">(Nov 26 2019 at 21:15)</a>:</h4>
<p><span aria-label="upside down" class="emoji emoji-1f643" role="img" title="upside down">:upside_down:</span></p>



<a name="181964861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181964861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181964861">(Nov 26 2019 at 21:16)</a>:</h4>
<p>I'll give this a try this evening.</p>



<a name="181964992"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181964992" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181964992">(Nov 26 2019 at 21:17)</a>:</h4>
<p>And <code>push_region_constraints</code> should be be replaced with an assertion of <code>data.is_empty()</code></p>



<a name="181965096"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181965096" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181965096">(Nov 26 2019 at 21:17)</a>:</h4>
<p>Maybe...</p>



<a name="181965168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181965168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181965168">(Nov 26 2019 at 21:18)</a>:</h4>
<p>Actually, yes, do that and when it ICEs ask for help.</p>



<a name="181965242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181965242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181965242">(Nov 26 2019 at 21:18)</a>:</h4>
<p>In other words whether a type implements <code>StructuralPartialEq</code> should not be dependent on lifetimes since they should all be erased by the time we call this?</p>



<a name="181965713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181965713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181965713">(Nov 26 2019 at 21:24)</a>:</h4>
<p>They should all be erased. There might be some issues with late-bound regions and universes, but I'm hoping that it works for now.</p>



<a name="181965729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181965729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181965729">(Nov 26 2019 at 21:25)</a>:</h4>
<p>And in the final value they're all <code>'static</code></p>



<a name="181965736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181965736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181965736">(Nov 26 2019 at 21:25)</a>:</h4>
<p>or late-bound</p>



<a name="181965770"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181965770" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181965770">(Nov 26 2019 at 21:26)</a>:</h4>
<p>I guess not in associated constants, sigh...</p>



<a name="181966229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181966229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181966229">(Nov 26 2019 at 21:30)</a>:</h4>
<p>Hmm, well I can always use the same approach as <span class="user-mention silent" data-user-id="116083">pnkfelix</span> and start caching it later.</p>



<a name="181966313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181966313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181966313">(Nov 26 2019 at 21:31)</a>:</h4>
<p>Presumably I can do no worse than their PR?</p>



<a name="181966904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/181966904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#181966904">(Nov 26 2019 at 21:38)</a>:</h4>
<p>I guess</p>



<a name="182392241"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182392241" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182392241">(Dec 02 2019 at 21:30)</a>:</h4>
<p><span class="user-mention" data-user-id="116083">@pnkfelix</span> I implemented a barebones structural match <code>Qualif</code> in a <a href="https://github.com/rust-lang/rust/compare/master...ecstatic-morse:qualif-structural-match" target="_blank" title="https://github.com/rust-lang/rust/compare/master...ecstatic-morse:qualif-structural-match">WIP branch</a>. The next step would be to check the results of <code>mir_const_qualif</code> in <a href="https://github.com/rust-lang/rust/compare/master...ecstatic-morse:qualif-structural-match#diff-e826542d6f24137d5b0b5ae333230529R856" target="_blank" title="https://github.com/rust-lang/rust/compare/master...ecstatic-morse:qualif-structural-match#diff-e826542d6f24137d5b0b5ae333230529R856"><code>hair/pattern/mod.rs</code></a>. Do you have any opinions on the best way to do this?</p>



<a name="182429350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182429350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182429350">(Dec 03 2019 at 09:31)</a>:</h4>
<p><span class="user-mention" data-user-id="118594">@ecstatic-morse</span> I was assuming that you'd have to put the check somewhere else; doesn't <code>mir_const_qualif</code>operate on MIR? the code in <code>hair/pattern/mod.rs</code> is transforming HIR to HAIR, so its running too early to apply something that operates on MIR.</p>



<a name="182579991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182579991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182579991">(Dec 04 2019 at 17:45)</a>:</h4>
<p><span class="user-mention" data-user-id="116083">@pnkfelix</span> Is it not possible for HIR -&gt; HAIR lowering of one item to depend on HIR -&gt; HAIR -&gt; MIR being completed for another? I'm not very familiar with the constraints of the query system.</p>



<a name="182580140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182580140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182580140">(Dec 04 2019 at 17:47)</a>:</h4>
<p>Hmm maybe that is fine ....</p>



<a name="182580217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182580217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182580217">(Dec 04 2019 at 17:47)</a>:</h4>
<p>Perhaps a better time for this check would be HAIR -&gt; MIR lowering?</p>



<a name="182580396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182580396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182580396">(Dec 04 2019 at 17:49)</a>:</h4>
<p>Although it looks like we would have to keep a <code>DefId</code> in <code>hair::PatKind</code></p>



<a name="182580553"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182580553" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182580553">(Dec 04 2019 at 17:51)</a>:</h4>
<p>I'll try to work on my branch some more I guess</p>



<a name="182747979"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182747979" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182747979">(Dec 06 2019 at 10:39)</a>:</h4>
<p>I'll try to look at your branch now</p>



<a name="182753006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182753006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182753006">(Dec 06 2019 at 11:53)</a>:</h4>
<p><span class="user-mention" data-user-id="118594">@ecstatic-morse</span> what is the <code>self.indirectly_mutable(..)</code> check doing here? is that a cut-and-paste typo? <a href="https://github.com/rust-lang/rust/compare/master...ecstatic-morse:qualif-structural-match#diff-b0c62fbcd3affaac3e5bfcef42f9d4b0R116" target="_blank" title="https://github.com/rust-lang/rust/compare/master...ecstatic-morse:qualif-structural-match#diff-b0c62fbcd3affaac3e5bfcef42f9d4b0R116">https://github.com/rust-lang/rust/compare/master...ecstatic-morse:qualif-structural-match#diff-b0c62fbcd3affaac3e5bfcef42f9d4b0R116</a></p>



<a name="182754498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182754498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182754498">(Dec 06 2019 at 12:18)</a>:</h4>
<p>also, I am trying to understand the <code>Qualif</code> trait's API. I can see that the methods return booleans to signal whether they've seen "something bad" or not. But is there some way to record <em>what</em> the "something bad" was?</p>



<a name="182754954"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182754954" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182754954">(Dec 06 2019 at 12:24)</a>:</h4>
<p>By <em>what</em> do you mean the exact location of the bad thing? Or the kind of bad thing? Becaues the kind is the type implementing the trait</p>



<a name="182756378"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182756378" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182756378">(Dec 06 2019 at 12:43)</a>:</h4>
<p>the kind of the bad thing... or at least some specific info about it other than its existence</p>



<a name="182756388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182756388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182756388">(Dec 06 2019 at 12:43)</a>:</h4>
<p>I thought part of what happens here is you do a traversal of the MIR</p>



<a name="182756403"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182756403" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182756403">(Dec 06 2019 at 12:43)</a>:</h4>
<p>like, the whole const is "bad"</p>



<a name="182756418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182756418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182756418">(Dec 06 2019 at 12:43)</a>:</h4>
<p>but its bad because of something we encountered while traversing it</p>



<a name="182756516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182756516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182756516">(Dec 06 2019 at 12:44)</a>:</h4>
<p>but maybe I simply misinterpreted the Qualif trait itself.</p>



<a name="182757280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182757280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182757280">(Dec 06 2019 at 12:55)</a>:</h4>
<p>concrete example, for structural_match: Say we're analyzing <code>const FOO: (u32, Inner) = (0, Inner::new());</code>, where <code>Inner</code> does not derive PartialEq+Eq. So we do <code>tcx.at(span).mir_const_qualif(foo_def_id)</code>. But I want the diagnostic to report the problem is with the use of <code>Inner</code>.</p>



<a name="182758654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182758654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182758654">(Dec 06 2019 at 13:12)</a>:</h4>
<p>Hmm... I don't think there's a scheme for pointing to the source of the failure</p>



<a name="182758674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182758674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182758674">(Dec 06 2019 at 13:13)</a>:</h4>
<p>Maybe qualifs should have <code>Result&lt;(), SomeInfo&gt;</code> instead of just <code>bool</code></p>



<a name="182758956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182758956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182758956">(Dec 06 2019 at 13:16)</a>:</h4>
<p>yeah; though I suspect <code>SomeInfo</code> might need to be customized per-analysis (so that's yet another associated type on <code>trait Qualif</code>)</p>



<a name="182786295"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182786295" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182786295">(Dec 06 2019 at 17:56)</a>:</h4>
<p><code>Qualif</code> is basically a MIR Visitor that can return a boolean, with <code>*_structurally</code> in place of <code>super_*</code>. However, <code>Qualif</code> is fine-grained; it only visits things <code>Rvalue</code>s and things that can appear in <code>Rvalue</code>s, not entire <code>Statement</code>s or <code>Body</code>s.</p>
<p>The return value of the <code>in_*</code> methods is used to set/clear bits during dataflow analysis, so there's no way to find which <code>Rvalue</code> caused a qualif to appear in a final value at present. It's possible for a qualif to come from multiple places. We would need to construct an actual data dependency graph (a use-def chain) for this. This would also benefit other implementers of the <code>Qualif</code> trait.</p>
<p><code>indirectly_mutable</code> is a safety measure for when <code>&amp;mut</code> is allowed in constants. If a reference that would allow mutation is created to any local, we fall back to conservative, type-based qualification (<code>in_any_value_of_ty</code>), since we can no longer use dataflow to reason about the value in a local.</p>



<a name="182919921"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182919921" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182919921">(Dec 09 2019 at 02:33)</a>:</h4>
<p>I worked on my branch a bit more. Looks like we need a <code>is_definitely_not_structural_match</code> that, e.g., returns <code>true</code> for <code>NoDerive</code> but <code>false</code> for <code>Option&lt;NoDerive&gt;</code>. This is the equivalent of <code>has_dtor</code> used for the <code>NeedsDrop</code> qualif, which is powered by the <a href="https://github.com/rust-lang/rust/blob/41601a8c95240cada94c13466a1fea02e5fe87ed/src/librustc_typeck/check/mod.rs#L804" target="_blank" title="https://github.com/rust-lang/rust/blob/41601a8c95240cada94c13466a1fea02e5fe87ed/src/librustc_typeck/check/mod.rs#L804"><code>adt_destructor</code> query</a></p>



<a name="182920207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182920207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182920207">(Dec 09 2019 at 02:43)</a>:</h4>
<p><span class="user-mention" data-user-id="116083">@pnkfelix</span> I don't think this is as simple as "does this type implement <code>{Partial,}Eq</code> but not <code>Structural{Partial,}Eq</code>", since  the impl for e.g. <code>Option&lt;T&gt;</code> looks like <code>impl&lt;T: StructuralEq&gt; StructuralEq for Option&lt;T&gt; {}</code>. Is this right?</p>



<a name="182920267"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182920267" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182920267">(Dec 09 2019 at 02:45)</a>:</h4>
<p>I suppose we could look for <em>any</em> impl of <code>StructuralEq</code> for the type in question, even if it's not applicable to the fully substituted type.</p>



<a name="182921562"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182921562" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182921562">(Dec 09 2019 at 03:23)</a>:</h4>
<p>Ah, I just saw <a href="https://github.com/rust-lang/rust/blob/b7176b44a203322c834302f3b515f8c10a54f2c1/src/libsyntax_ext/deriving/mod.rs#L79-L81" target="_blank" title="https://github.com/rust-lang/rust/blob/b7176b44a203322c834302f3b515f8c10a54f2c1/src/libsyntax_ext/deriving/mod.rs#L79-L81">this comment</a>, which suggests that there are no where clauses on the <code>StructuralEq</code> impl for <code>Option</code>.</p>



<a name="182922630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182922630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182922630">(Dec 09 2019 at 03:57)</a>:</h4>
<p>If that's the case I'm doing something wrong <span aria-label="half frown" class="emoji emoji-1f615" role="img" title="half frown">:half_frown:</span></p>



<a name="182923111"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182923111" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182923111">(Dec 09 2019 at 04:11)</a>:</h4>
<p>Specifically, <code>NotStructuralMatch::in_rvalue</code> is returning <code>true</code> for <code>Option::&lt;NoDerive&gt;::None</code>, but <code>Option&lt;NoDerive</code> should implement <code>StructuralEq</code> no?</p>



<a name="182926970"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182926970" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182926970">(Dec 09 2019 at 06:05)</a>:</h4>
<p>Correct. It indeed sounds like your code does something wrong. (When I was skimming it, I think I had vague worries that it would fall into the conservative type-structure traversal. Not sure.)</p>



<a name="182995892"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182995892" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182995892">(Dec 09 2019 at 20:24)</a>:</h4>
<p>I'm getting:</p>
<div class="codehilite"><pre><span></span> FulfillmentError(Obligation(predicate=Binder(TraitPredicate(&lt;T as std::marker::Sized&gt;)), depth=1),Unimplemented),
</pre></div>


<p>as the reason <code>StructuralEq</code> cannot be fulfilled for <code>Option&lt;NoDerive&gt;</code>. Does this mean I'm not passing  the right <code>ParamEnv</code> or something? Also, shouldn't the generated impl have<code>?Sized</code> anyways?</p>
<p>Also, it seems that <code>StructuralEq</code> is not implemented for tuples, so I needed to special case those as well.</p>



<a name="182997332"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/182997332" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#182997332">(Dec 09 2019 at 20:39)</a>:</h4>
<p>Same thing for references. Is this intended?</p>



<a name="183012085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/183012085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#183012085">(Dec 09 2019 at 23:31)</a>:</h4>
<p><span class="user-mention" data-user-id="116083">@pnkfelix</span> ^</p>



<a name="183012271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/183012271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#183012271">(Dec 09 2019 at 23:34)</a>:</h4>
<p>Hmm. That is not intended</p>



<a name="183012371"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/183012371" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#183012371">(Dec 09 2019 at 23:35)</a>:</h4>
<p>Oh of course</p>



<a name="183012395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/183012395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#183012395">(Dec 09 2019 at 23:35)</a>:</h4>
<p>The current checker is based on the one that used attributes on ADTs</p>



<a name="183012461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/183012461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#183012461">(Dec 09 2019 at 23:36)</a>:</h4>
<p>So it handles the traversal of non-ADT types itself</p>



<a name="183012501"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/183012501" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#183012501">(Dec 09 2019 at 23:36)</a>:</h4>
<p>But i don’t object to adding blanket impls of StructuralTraits for those types</p>



<a name="183012506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/183012506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#183012506">(Dec 09 2019 at 23:37)</a>:</h4>
<p>I'm guessing you've handled this on your branch. I'm working off master but using your tests</p>



<a name="183012599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/183012599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#183012599">(Dec 09 2019 at 23:38)</a>:</h4>
<p>Regarding ?Sized: can an unsized type ever be used in a pattern?</p>



<a name="183012635"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/183012635" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#183012635">(Dec 09 2019 at 23:38)</a>:</h4>
<p>I guess slices and str, of course</p>



<a name="183012662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/183012662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#183012662">(Dec 09 2019 at 23:39)</a>:</h4>
<p>But those both feel like special cased instances, not examples of a more general form ...?</p>



<a name="183012666"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/183012666" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#183012666">(Dec 09 2019 at 23:39)</a>:</h4>
<p>The version of <a href="https://github.com/rust-lang/rust/blob/master/src/librustc/ty/structural_match.rs#L65" target="_blank" title="https://github.com/rust-lang/rust/blob/master/src/librustc/ty/structural_match.rs#L65"><code>type_marked_structural</code></a> from <code>master</code> is returning <code>false</code> for <code>Option</code> at the moment, even though the <code>NoDerive</code> struct from your tests is <code>Sized</code> (obvs).</p>



<a name="183012696"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/183012696" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#183012696">(Dec 09 2019 at 23:40)</a>:</h4>
<p>Anyway I need to go to bed now, it’s well past my bedtime and I’m unwell</p>



<a name="183012743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/183012743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#183012743">(Dec 09 2019 at 23:40)</a>:</h4>
<p>I don't know enough about patterns, but at least for <code>Option</code> it seems like the <code>Sized</code> bound is needed.</p>



<a name="183012752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/183012752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#183012752">(Dec 09 2019 at 23:40)</a>:</h4>
<p>No problem! Get better.</p>



<a name="183110520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/183110520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#183110520">(Dec 10 2019 at 22:43)</a>:</h4>
<p>I'm gonna hit pause on this until I can land a refactoring of the <code>Qualif</code> trait. My hope is that people who know more about the <code>#[structural_match]</code>/<code>StructuralPartialEq</code> system will be empowered to switch to a MIR-based approach if the intended use of the <code>Qualif</code> trait is clearer.</p>



<a name="183110600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/183110600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#183110600">(Dec 10 2019 at 22:44)</a>:</h4>
<p>I've been making a lot of dumb mistakes in this branch <span aria-label="lol" class="emoji emoji-1f606" role="img" title="lol">:lol:</span>, and the refactoring will help me feel more productive as well.</p>



<a name="183520133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/long%20term%20plan%20for%20const%20pattern%20codegen%20%2366120/near/183520133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/long.20term.20plan.20for.20const.20pattern.20codegen.20.2366120.html#183520133">(Dec 16 2019 at 05:07)</a>:</h4>
<p>I did a refactoring of the <code>Qualif</code> trait's API in <a href="https://github.com/rust-lang/rust/issues/67335" target="_blank" title="https://github.com/rust-lang/rust/issues/67335">#67335</a>, and a made a proof-of-concept for structural match qualification in <a href="https://github.com/rust-lang/rust/issues/67343" target="_blank" title="https://github.com/rust-lang/rust/issues/67343">#67343</a>. It's hard to implement <code>in_any_value_of_ty</code> precisely, since there's no trivial way to differentiate between a <code>struct</code> that implements <code>StructuralPartialEq</code> (which is always <code>structural_match</code>) and <code>Option&lt;T&gt;</code>(which is only sometimes <code>structural_match</code>).</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>